/*
 * $Id: SqlTimestampConverter.java 30 2006-06-08 13:26:40Z wjx $
 */
package	com.someok.utils.datetime.converters;

import java.sql.Timestamp;

import com.someok.utils.datetime.DateTimeStamp;
import com.someok.utils.datetime.JDateTime;

/**
 *
 *
 * <p><a href="SqlTimestampConverter.java.html"><i>View Source</i></a></p>
 *
 * @author wjx
 * @version $Revision: 30 $ $Date: 2006-06-08 21:26:40 +0800 (星期四, 08 六月 2006) $
 */
public class SqlTimestampConverter implements com.someok.utils.datetime.JdtConverter {

	public void load(JDateTime gt, Object o) {
		if (o instanceof Timestamp) {
			Timestamp t = (Timestamp) o;
			gt.set(1900 + t.getYear(), t.getMonth() + 1, t.getDate(), t.getHours(), t.getMinutes(), (double)t.getSeconds() + t.getNanos() / 1000000000.0d);
		}
	}

	public Object get(JDateTime gt) {
		DateTimeStamp time = gt.getDateTimeStamp();
		return new Timestamp(time.year - 1900, time.month - 1, time.day, time.hour, time.minute, (int)time.second, ((int)((time.second - (int)time.second) * 1000000000)));
	}


	public void store(JDateTime gt, Object o) {
		if (o instanceof Timestamp) {
			Timestamp ts = (Timestamp) o;
			DateTimeStamp time = gt.getDateTimeStamp();
			ts.setYear(time.year - 1900);
			ts.setMonth(time.month - 1);
			ts.setDate(time.day);
			ts.setHours(time.hour);
			ts.setMinutes(time.minute);
			ts.setSeconds((int)time.second);
			ts.setNanos(((int)((time.second - (int)time.second) * 1000000000)));
		}
	}
}
